package com.jsb.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jsb.mapper.UserMapper;
import com.jsb.model.User;
import com.jsb.model.UserExample;
import com.jsb.model.UserExample.Criteria;

@Service
public class UserService{
	
	@Resource
	private UserMapper userMapper;
	
	public void addUser(User user) {
		userMapper.insertSelective(user);
	}
	
	public void delUserByPhoneNumber(String phoneNumber) {
		userMapper.deleteByPrimaryKey(phoneNumber);
	}
	
	public void updateUser(User user) {
		userMapper.updateByPrimaryKeySelective(user);
	}
	
	public void updateUserByExample(User user,UserExample userExample){
	    userMapper.updateByExampleSelective(user,userExample);
	}
	
	public User getUserByPhoneNumber(String phoneNumber) {
		return userMapper.selectByPrimaryKey(phoneNumber);
	}
	
	public List<User> getPageUser(UserExample userExample) {
		return userMapper.selectPage(userExample);
	}
	
	public int countUser(UserExample userExample) {
		return userMapper.countByExample(userExample);
	}
	
	public List<User> selectByExample(UserExample example){
	    return userMapper.selectByExample(example);
	}
	
	public List<User> getUserByLikePhone(String phone){
		UserExample example = new UserExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andPhoneLike("%"+phone+"%");
		List<User> users = userMapper.selectByExample(example );
		return users;
	}
}
